package wk.demo.fragments.dialogFragment;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.luoye.bzijkplayer.R;


public abstract class WkPlayerBaseDialogFragment extends DialogFragment {
    @Override
    public void onStart() {
        super.onStart();


        Window window = getDialog().getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        //当FLAG_DIM_BEHIND设置后生效。该变量指示后面的窗口变暗的程度。1.0表示完全不透明，0.0表示没有变暗。
        params.dimAmount = 0.2f;
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.TOP | Gravity.END;
        window.setAttributes(params);

        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));


        window.getDecorView().setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (isCancelable()) {
                        dismiss();
                    }
                    return true;
                }
                return true;
            }
        });
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // 出入动画
        Window window = getDialog().getWindow();
        window.getAttributes().windowAnimations = R.style.AnimationRightFade;
    }

    private boolean isShowFragment = false;
    public boolean isShowFragment() {
        return isShowFragment;
    }

    @Override
    public void show(FragmentManager manager, String tag) {
        super.show(manager, tag);
         isShowFragment = true;
    }


    @Override
    public void dismiss() {
        super.dismiss();
        isShowFragment = false;
    }

}
